﻿namespace ComTools
{
    using System;
    using System.IO;
    using System.Management;
    using System.Security.Cryptography;
    using System.Text;
    using Microsoft.Win32;
	internal class myCodeEncryption
	{
		// Token: 0x06000078 RID: 120 RVA: 0x00008784 File Offset: 0x00006984
		public void user_CreateRSAKey(string PrivateKeyPath, string PublicKeyPath)
		{
			try
			{
				RSACryptoServiceProvider provider = new RSACryptoServiceProvider();
				this.user_CreatePrivateKeyXML(PrivateKeyPath, provider.ToXmlString(true));
				this.user_CreatePublicKeyXML(PublicKeyPath, provider.ToXmlString(false));
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}

		// Token: 0x06000079 RID: 121 RVA: 0x000087C8 File Offset: 0x000069C8
		public void user_CreatePublicKeyXML(string path, string publickey)
		{
			try
			{
				FileStream fileStream = new FileStream(path, FileMode.Create);
				StreamWriter streamWriter = new StreamWriter(fileStream);
				streamWriter.WriteLine(publickey);
				streamWriter.Close();
				fileStream.Close();
			}
			catch
			{
				throw;
			}
		}

		// Token: 0x0600007A RID: 122 RVA: 0x00008808 File Offset: 0x00006A08
		public void user_CreatePrivateKeyXML(string path, string privatekey)
		{
			try
			{
				FileStream fileStream = new FileStream(path, FileMode.Create);
				StreamWriter streamWriter = new StreamWriter(fileStream);
				streamWriter.WriteLine(privatekey);
				streamWriter.Close();
				fileStream.Close();
			}
			catch
			{
				throw;
			}
		}

		// Token: 0x0600007B RID: 123 RVA: 0x00008848 File Offset: 0x00006A48
		public string user_ReadRSAPublicKey(string path)
		{
			StreamReader streamReader = new StreamReader(path);
			string publickey = streamReader.ReadToEnd();
			streamReader.Close();
			return publickey;
		}

		// Token: 0x0600007C RID: 124 RVA: 0x00008868 File Offset: 0x00006A68
		public string user_ReadRSAPrivateKey(string path)
		{
			StreamReader streamReader = new StreamReader(path);
			string privatekey = streamReader.ReadToEnd();
			streamReader.Close();
			return privatekey;
		}

		// Token: 0x0600007D RID: 125 RVA: 0x00008888 File Offset: 0x00006A88
		public string user_RSA_Encrypt(string xmlPublicKey, string m_strEncryptString)
		{
			string str2;
			try
			{
				RSACryptoServiceProvider rsacryptoServiceProvider = new RSACryptoServiceProvider();
				rsacryptoServiceProvider.FromXmlString(xmlPublicKey);
				byte[] bytes = Encoding.UTF8.GetBytes(m_strEncryptString);
				str2 = Convert.ToBase64String(rsacryptoServiceProvider.Encrypt(bytes, false));
			}
			catch (Exception ex)
			{
				throw ex;
			}
			return str2;
		}

		// Token: 0x0600007E RID: 126 RVA: 0x000088D0 File Offset: 0x00006AD0
		public string user_RSA_Decrypt(string xmlPrivateKey, string m_strDecryptString)
		{
			string str2;
			try
			{
				RSACryptoServiceProvider rsacryptoServiceProvider = new RSACryptoServiceProvider();
				rsacryptoServiceProvider.FromXmlString(xmlPrivateKey);
				byte[] rgb = Convert.FromBase64String(m_strDecryptString);
				byte[] buffer2 = rsacryptoServiceProvider.Decrypt(rgb, false);
				str2 = Encoding.UTF8.GetString(buffer2);
			}
			catch (Exception ex)
			{
				throw ex;
			}
			return str2;
		}

		// Token: 0x0600007F RID: 127 RVA: 0x00008918 File Offset: 0x00006B18
		public string user_GetHash_MD5(string m_strSource)
		{
			HashAlgorithm hashAlgorithm = HashAlgorithm.Create("MD5");
			byte[] bytes = Encoding.GetEncoding("GB2312").GetBytes(m_strSource);
			return Convert.ToBase64String(hashAlgorithm.ComputeHash(bytes));
		}

		// Token: 0x06000080 RID: 128 RVA: 0x0000894C File Offset: 0x00006B4C
		public string user_SignatureFormatter(string p_strKeyPrivate, string m_strHashbyteSignature)
		{
			byte[] rgbHash = Convert.FromBase64String(m_strHashbyteSignature);
			RSACryptoServiceProvider rsacryptoServiceProvider = new RSACryptoServiceProvider();
			rsacryptoServiceProvider.FromXmlString(p_strKeyPrivate);
			RSAPKCS1SignatureFormatter rsapkcs1SignatureFormatter = new RSAPKCS1SignatureFormatter(rsacryptoServiceProvider);
			rsapkcs1SignatureFormatter.SetHashAlgorithm("MD5");
			return Convert.ToBase64String(rsapkcs1SignatureFormatter.CreateSignature(rgbHash));
		}

		// Token: 0x06000081 RID: 129 RVA: 0x00008988 File Offset: 0x00006B88
		public bool user_SignatureDeformatter(string p_strKeyPublic, string p_strHashbyteDeformatter, string p_strDeformatterData)
		{
			bool result;
			try
			{
				byte[] rgbHash = Convert.FromBase64String(p_strHashbyteDeformatter);
				RSACryptoServiceProvider rsacryptoServiceProvider = new RSACryptoServiceProvider();
				rsacryptoServiceProvider.FromXmlString(p_strKeyPublic);
				RSAPKCS1SignatureDeformatter rsapkcs1SignatureDeformatter = new RSAPKCS1SignatureDeformatter(rsacryptoServiceProvider);
				rsapkcs1SignatureDeformatter.SetHashAlgorithm("MD5");
				byte[] rgbSignature = Convert.FromBase64String(p_strDeformatterData);
				if (rsapkcs1SignatureDeformatter.VerifySignature(rgbHash, rgbSignature))
				{
					result = true;
				}
				else
				{
					result = false;
				}
			}
			catch
			{
				result = false;
			}
			return result;
		}

		// Token: 0x06000082 RID: 130 RVA: 0x000089E8 File Offset: 0x00006BE8
		public string user_GetHardID()
		{
			string result;
			try
			{
				ManagementObjectCollection instances = new ManagementClass("Win32_DiskDrive").GetInstances();
				string strID = null;
				using (ManagementObjectCollection.ManagementObjectEnumerator enumerator = instances.GetEnumerator())
				{
					if (enumerator.MoveNext())
					{
						strID = ((ManagementObject)enumerator.Current).Properties["Model"].Value.ToString();
					}
				}
				result = strID.Trim();
			}
			catch
			{
				result = "unknow";
			}
			return result;
		}

		// Token: 0x06000083 RID: 131 RVA: 0x00008A78 File Offset: 0x00006C78
		public string user_GetCPUID()
		{
			string cpuInfo = "";
			foreach (ManagementBaseObject managementBaseObject in new ManagementClass("Win32_Processor").GetInstances())
			{
				cpuInfo = ((ManagementObject)managementBaseObject).Properties["ProcessorId"].Value.ToString();
			}
			return cpuInfo.Trim();
		}

		// Token: 0x06000084 RID: 132 RVA: 0x00008AF4 File Offset: 0x00006CF4
		public string user_GetMainBoardID()
		{
			ManagementObjectCollection instances = new ManagementClass("Win32_BaseBoard").GetInstances();
			string strID = null;
			using (ManagementObjectCollection.ManagementObjectEnumerator enumerator = instances.GetEnumerator())
			{
				if (enumerator.MoveNext())
				{
					strID = ((ManagementObject)enumerator.Current).Properties["SerialNumber"].Value.ToString();
				}
			}
			return strID.Trim();
		}

		// Token: 0x06000085 RID: 133 RVA: 0x00008B6C File Offset: 0x00006D6C
		public string GetMacAddress()
		{
			string result;
			try
			{
				string mac = "";
				foreach (ManagementBaseObject managementBaseObject in new ManagementClass("Win32_NetworkAdapterConfiguration").GetInstances())
				{
					ManagementObject mo = (ManagementObject)managementBaseObject;
					if ((bool)mo["IPEnabled"])
					{
						mac = mo["MacAddress"].ToString();
						break;
					}
				}
				result = mac;
			}
			catch
			{
				result = "unknow";
			}
			return result;
		}

		// Token: 0x06000086 RID: 134 RVA: 0x00008C08 File Offset: 0x00006E08
		private string user_ReadReg(string key)
		{
			string result;
			try
			{
				RegistryKey localMachine = Registry.LocalMachine;
				RegistryKey registryKey = localMachine.OpenSubKey("SOFTWARE/JX/Register");
				string temp = registryKey.GetValue(key).ToString();
				registryKey.Close();
				localMachine.Close();
				result = temp;
			}
			catch (Exception)
			{
				throw;
			}
			return result;
		}

		// Token: 0x06000087 RID: 135 RVA: 0x00008C5C File Offset: 0x00006E5C
		private void user_WriteReg(string key, string value)
		{
			try
			{
				RegistryKey registryKey = Registry.LocalMachine.CreateSubKey("SOFTWARE/JX/Register");
				registryKey.SetValue(key, value);
				registryKey.Close();
			}
			catch (Exception)
			{
				throw;
			}
		}

		// Token: 0x06000088 RID: 136 RVA: 0x00008C9C File Offset: 0x00006E9C
		public void user_InitialReg(string path)
		{
			Registry.LocalMachine.CreateSubKey("SOFTWARE/JX/Register");
			Random ra = new Random();
			string publickey = this.user_ReadRSAPublicKey(path);
			if (Registry.LocalMachine.OpenSubKey("SOFTWARE/JX/Register").ValueCount <= 0)
			{
				this.user_WriteReg("RegisterRandom", ra.Next(1, 100000).ToString());
				this.user_WriteReg("RegisterPublicKey", publickey);
				return;
			}
			this.user_WriteReg("RegisterPublicKey", publickey);
		}

		// Token: 0x06000089 RID: 137 RVA: 0x00008D18 File Offset: 0x00006F18
		public string user_AES_Encrypt(string toEncrypt, string key)
		{
			byte[] keyArray = Encoding.UTF8.GetBytes(key);
			byte[] toEncryptArray = Encoding.UTF8.GetBytes(toEncrypt);
			byte[] resultArray = new RijndaelManaged
			{
				Key = keyArray,
				Mode = CipherMode.ECB,
				Padding = PaddingMode.PKCS7
			}.CreateEncryptor().TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
			return Convert.ToBase64String(resultArray, 0, resultArray.Length);
		}

		// Token: 0x0600008A RID: 138 RVA: 0x00008D74 File Offset: 0x00006F74
		public string user_AES_Decrypt(string toDecrypt, string key)
		{
			byte[] keyArray = Encoding.UTF8.GetBytes(key);
			byte[] toEncryptArray = Convert.FromBase64String(toDecrypt);
			byte[] resultArray = new RijndaelManaged
			{
				Key = keyArray,
				Mode = CipherMode.ECB,
				Padding = PaddingMode.PKCS7
			}.CreateDecryptor().TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
			return Encoding.UTF8.GetString(resultArray);
		}

		// Token: 0x0600008B RID: 139 RVA: 0x00008DCC File Offset: 0x00006FCC
		public string user_3DES_Encrypt(string data, string key)
		{
			ICryptoTransform DESEncrypt = new TripleDESCryptoServiceProvider
			{
				Key = Encoding.Default.GetBytes(key),
				Mode = CipherMode.ECB,
				Padding = PaddingMode.None
			}.CreateEncryptor();
			byte[] Buffer = Encoding.Default.GetBytes(data);
			return Encoding.ASCII.GetString(DESEncrypt.TransformFinalBlock(Buffer, 0, Buffer.Length));
		}

		// Token: 0x0600008C RID: 140 RVA: 0x00008E24 File Offset: 0x00007024
		public string user_3DES_Decrypt(string data, string key)
		{
			ICryptoTransform DESDecrypt = new TripleDESCryptoServiceProvider
			{
				Key = Encoding.Default.GetBytes(key),
				Mode = CipherMode.ECB,
				Padding = PaddingMode.None
			}.CreateDecryptor();
			string result = "";
			try
			{
				byte[] Buffer = Encoding.Default.GetBytes(data);
				result = Encoding.ASCII.GetString(DESDecrypt.TransformFinalBlock(Buffer, 0, Buffer.Length));
			}
			catch (Exception)
			{
			}
			return result;
		}

		// Token: 0x0600008D RID: 141 RVA: 0x00008E9C File Offset: 0x0000709C
		public static string user_GetRandomNumber()
		{
			return myCodeEncryption.GetRandomStringFromIntArray(myCodeEncryption.intArray(myCodeEncryption.intCount, myCodeEncryption.intTypeCount));
		}

		// Token: 0x0600008E RID: 142 RVA: 0x00008EB4 File Offset: 0x000070B4
		private static int[] intArray(int intCount, int intTypeCount)
		{
			int[] intArr = new int[intTypeCount];
			int intTemp = 0;
			Random ranNumber = new Random(DateTime.Now.Millisecond);
			for (int i = 0; i < intTypeCount - 1; i++)
			{
				int intTempNumber;
				do
				{
					intTempNumber = ranNumber.Next(0, intCount);
				}
				while (intTemp + intTempNumber > intCount);
				intTemp += intTempNumber;
				intArr[i] = intTempNumber;
			}
			intArr[intTypeCount - 1] = intCount - intTemp;
			return intArr;
		}

		// Token: 0x0600008F RID: 143 RVA: 0x00008F14 File Offset: 0x00007114
		private static string GetRandomStringFromIntArray(int[] intArrayNumber)
		{
			Random CharRand = new Random(DateTime.Now.Millisecond);
			string strTemp = "";
			for (int i = 0; i < intArrayNumber.Length; i++)
			{
				for (int j = 0; j < intArrayNumber[i]; j++)
				{
					if (i == 0)
					{
						strTemp += Convert.ToChar(CharRand.Next(65, 90)).ToString();
					}
					if (i == 1)
					{
						strTemp += Convert.ToChar(CharRand.Next(97, 122)).ToString();
					}
					if (i == 2)
					{
						strTemp += Convert.ToChar(CharRand.Next(49, 57)).ToString();
					}
				}
			}
			return strTemp;
		}

		// Token: 0x04000036 RID: 54
		private static int intCount = 24;

		// Token: 0x04000037 RID: 55
		private static int intTypeCount = 3;
	}
}
